package com.qiyeji.real_estate.service;

import com.qiyeji.real_estate.entity.StaffPerformance;
import com.qiyeji.real_estate.entity.staff;
import com.qiyeji.real_estate.mapper.StaffPerformanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

@Service
public class StaffPerformanceService {

    @Autowired
    StaffPerformanceMapper staffPerformanceMapper;

    @Autowired
    StaffService staffService;


    public CopyOnWriteArrayList<StaffPerformance> getStaffPerformanceByDateForExcel(String date) {
        CopyOnWriteArrayList<StaffPerformance> projectNum = staffPerformanceMapper.getProjectNumForExcel(date);
        List<staff> staffs = staffService.getAllStaff();
        CopyOnWriteArrayList<StaffPerformance> workTime = staffPerformanceMapper.getWorkTimeForExcel(date);
        CopyOnWriteArrayList<StaffPerformance> Result = new CopyOnWriteArrayList<>();
        for (staff temp: staffs) {
            StaffPerformance s = new StaffPerformance();
            s.setScode(temp.getScode());
            s.setSname(temp.getSname());
            s.setJob(temp.getJob());
            s.setDate(date);
            for (StaffPerformance staffPerformance: projectNum){
                if (s.getScode().equals(staffPerformance.getScode())){
                    s.setNumOfProject(staffPerformance.getNumOfProject());
                }
            }
            for (StaffPerformance staffPerformance: workTime) {
                if (s.getScode().equals(staffPerformance.getScode())){
                    s.setHoursOfWork(staffPerformance.getHoursOfWork());
                }
            }
            Result.add(s);
        }

        return Result;
    }
}
